filechooser: Drop the ::selection-changed signal
authorMatthias Clasen <mclasen@redhat.com>
Thu, 9 Jul 2020 06:06:31 +0000 (02:06 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 9 Jul 2020 06:06:31 +0000 (02:06 -0400)
This signal does not work on native file choosers,
and it exposes internals of the widget that should
not be public. And it is just not very interesting.

gtk/gtkfilechooser.c
gtk/gtkfilechooserbutton.c
gtk/gtkfilechooserdialog.c
gtk/gtkfilechoosernative.c
gtk/gtkfilechooserutils.c
gtk/gtkfilechooserwidget.c
gtk/ui/gtkfilechooserdialog.ui

index 9248b0ecca8581068c69b4cfe98fae5f5dc0ad02..a6c28424adb19d0ebdf7dfc2a76432934e9bfccc 100644 (file)
@@ -79,29 +79,6 @@ G_DEFINE_INTERFACE (GtkFileChooser, gtk_file_chooser, G_TYPE_OBJECT);
 static void
 gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
 {
-  GType iface_type = G_TYPE_FROM_INTERFACE (iface);
-
-  /**
-   * GtkFileChooser::selection-changed:
-   * @chooser: the object which received the signal.
-   *
-   * This signal is emitted when there is a change in the set of selected files
-   * in a #GtkFileChooser.  This can happen when the user modifies the selection
-   * with the mouse or the keyboard, or when explicitly calling functions to
-   * change the selection.
-   *
-   * Normally you do not need to connect to this signal, as it is easier to wait
-   * for the file chooser to finish running, and then to get the list of
-   * selected files using the functions mentioned below.
-   */
-  g_signal_new (I_("selection-changed"),
-                iface_type,
-                G_SIGNAL_RUN_LAST,
-                G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
-                NULL, NULL,
-                NULL,
-                G_TYPE_NONE, 0);
-
   g_object_interface_install_property (iface,
                                        g_param_spec_enum ("action",
                                                           P_("Action"),
index cf63e745b6d2d1d84b9bec99ba2693681a1eda09..3708da658851a197472495c573e842a5f6f9d882 100644 (file)
@@ -627,7 +627,6 @@ emit_selection_changed_if_changing_selection (GtkFileChooserButton *button)
   if (button->is_changing_selection)
     {
       button->is_changing_selection = FALSE;
-      g_signal_emit_by_name (button, "selection-changed");
     }
 }
 
@@ -2516,8 +2515,6 @@ common_response_cb (GtkFileChooserButton *button,
       response == GTK_RESPONSE_OK)
     {
       save_inactive_state (button);
-
-      g_signal_emit_by_name (button, "selection-changed");
     }
   else
     {
index 8e8e70c1d6c9a5d3d96c1c20689a60ce31539ef3..a7bc1dd15f21d2202b2e37b938b2b0508290b853 100644 (file)
@@ -267,8 +267,6 @@ static void     gtk_file_chooser_dialog_size_allocate (GtkWidget            *wid
                                                        int                    baseline);
 static void     file_chooser_widget_response_requested (GtkWidget            *widget,
                                                         GtkFileChooserDialog *dialog);
-static void     file_chooser_widget_selection_changed (GtkWidget            *widget,
-                                                        GtkFileChooserDialog *dialog);
 
 static void response_cb (GtkDialog *dialog,
                          gint       response_id);
@@ -309,7 +307,6 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserDialog, buttons);
   gtk_widget_class_bind_template_callback (widget_class, response_cb);
   gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_response_requested);
-  gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_selection_changed);
 }
 
 static void
@@ -364,26 +361,6 @@ is_accept_response_id (gint response_id)
           response_id == GTK_RESPONSE_APPLY);
 }
 
-static void
-file_chooser_widget_selection_changed (GtkWidget            *widget,
-                                       GtkFileChooserDialog *dialog)
-{
-  GtkFileChooserDialogPrivate *priv = gtk_file_chooser_dialog_get_instance_private (dialog);
-  GtkWidget *button;
-  GListModel *files;
-  gboolean sensitive;
-
-  button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
-  if (button == NULL)
-    return;
-
-  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->widget));
-  sensitive = (g_list_model_get_n_items (files) > 0);
-  gtk_widget_set_sensitive (button, sensitive);
-
-  g_object_unref (files);
-}
-
 static void
 file_chooser_widget_response_requested (GtkWidget            *widget,
                                         GtkFileChooserDialog *dialog)
index 6dfd2960029ec7014fe8cecba4f0b2cacb691ee7..b6f7a9b01b3a2fa9119f5d1676ff65910721e425 100644 (file)
  * possible to use with #GtkFileChooserNative, as such use would
  * prohibit the use of a native dialog.
  *
- * There is no support for the signals that are emitted when the user
- * navigates in the dialog, including:
- * * #GtkFileChooser::selection-changed
- *
- * If you need any of the above you will have to use #GtkFileChooserDialog directly.
- *
  * No operations that change the dialog work while the dialog is visible.
  * Set all the properties that are required before showing the dialog.
  *
index b68fe534ff7b014db32dd3ce123e15e08a830ee8..0c62e8d590db3b4210280058418f4ff5041575b5 100644 (file)
@@ -56,8 +56,6 @@ static GListModel *   delegate_get_shortcut_folders   (GtkFileChooser    *choose
 static void           delegate_notify                 (GObject           *object,
                                                       GParamSpec        *pspec,
                                                       gpointer           data);
-static void           delegate_selection_changed      (GtkFileChooser    *chooser,
-                                                      gpointer           data);
 
 static void           delegate_add_choice             (GtkFileChooser  *chooser,
                                                        const char      *id,
@@ -164,8 +162,6 @@ _gtk_file_chooser_set_delegate (GtkFileChooser *receiver,
   g_object_set_data (G_OBJECT (receiver), I_("gtk-file-chooser-delegate"), delegate);
   g_signal_connect (delegate, "notify",
                    G_CALLBACK (delegate_notify), receiver);
-  g_signal_connect (delegate, "selection-changed",
-                   G_CALLBACK (delegate_selection_changed), receiver);
 }
 
 GQuark
@@ -307,13 +303,6 @@ delegate_notify (GObject    *object,
     g_object_notify (data, pspec->name);
 }
 
-static void
-delegate_selection_changed (GtkFileChooser *chooser,
-                           gpointer        data)
-{
-  g_signal_emit_by_name (data, "selection-changed");
-}
-
 GSettings *
 _gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
 {
index 01443dcba7833a71b1655072f4090840e398ed74..ac9e8721a10000b432012ed6416f708efdf7beea 100644 (file)
@@ -2220,14 +2220,66 @@ set_icon_cell_renderer_fixed_size (GtkFileChooserWidget *impl)
                                     ypad * 2 + ICON_SIZE);
 }
 
+static GtkWidget *
+get_accept_action_widget (GtkDialog *dialog,
+                          gboolean   sensitive_only)
+{
+  gint response[] = {
+    GTK_RESPONSE_ACCEPT,
+    GTK_RESPONSE_OK,
+    GTK_RESPONSE_YES,
+    GTK_RESPONSE_APPLY
+  };
+  gint i;
+  GtkWidget *widget;
+
+  for (i = 0; i < G_N_ELEMENTS (response); i++)
+    {
+      widget = gtk_dialog_get_widget_for_response (dialog, response[i]);
+      if (widget)
+        {
+          if (!sensitive_only)
+            return widget;
+
+          if (gtk_widget_is_sensitive (widget))
+            return widget;
+        }
+    }
+
+  return NULL;
+}
+
+static void
+update_default (GtkFileChooserWidget *impl)
+{
+  GtkWidget *dialog;
+  GtkWidget *button;
+  GListModel *files;
+  gboolean sensitive;
+
+  dialog = gtk_widget_get_ancestor (GTK_WIDGET (impl), GTK_TYPE_DIALOG);
+  if (dialog == NULL)
+    return;
+
+  button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
+  if (button == NULL)
+    return;
+
+  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (impl));
+  sensitive = (g_list_model_get_n_items (files) > 0);
+  gtk_widget_set_sensitive (button, sensitive);
+
+  g_object_unref (files);
+}
+
 static gboolean
 location_changed_timeout_cb (gpointer user_data)
 {
   GtkFileChooserWidget *impl = user_data;
 
   gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (impl));
-  g_signal_emit_by_name (impl, "selection-changed", 0);
 
+  update_default (impl);
   impl->location_changed_id = 0;
 
   return G_SOURCE_REMOVE;
@@ -5084,7 +5136,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
 
   g_object_notify (G_OBJECT (impl), "subtitle");
 
-  g_signal_emit_by_name (impl, "selection-changed", 0);
+  update_default (impl);
 
 out:
   g_object_unref (data->impl);
@@ -7004,8 +7056,7 @@ list_selection_changed (GtkTreeSelection     *selection,
     update_chooser_entry (impl);
 
   location_bar_update (impl);
-
-  g_signal_emit_by_name (impl, "selection-changed", 0);
+  update_default (impl);
 }
 
 static gboolean
index 57d5f3b7704f02a86b4edee0fad4ed14aab004e2..99b3700c69feed46f2cddfa910df5ace45ce3542 100644 (file)
@@ -21,7 +21,6 @@
             <property name="hexpand">1</property>
             <property name="vexpand">1</property>
             <signal name="response-requested" handler="file_chooser_widget_response_requested" swapped="no"/>
-            <signal name="selection-changed" handler="file_chooser_widget_selection_changed" swapped="no"/>
           </object>
         </child>
       </object>